package com.leyou.item.web;

import com.leyou.item.pojo.Category;
import com.leyou.item.service.CategoryService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * description: 商品分类接口
 * @author 朱正磊
 * @date 2021-03-26 19:07:48
 */
@RestController
@RequestMapping("category")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    /**
     * description: 根据父节点id查询商品分类
     * @author 朱正磊
     * @date 2021-03-26 19:10:14
     * @param pid 父节点id
     * @return 返回商品分类集合
     */
    @GetMapping("list")
    public ResponseEntity<List<Category>> queryCategoryListByPid(@RequestParam("pid") Long pid) {
        return ResponseEntity.ok(categoryService.queryCategoryListByPid(pid));
    }

    /**
     * description: 根据多个商品分类id查询商品分类集合
     * @author 朱正磊
     * @date 2021-04-06 23:06:12
     * @param ids 商品分类id集合
     * @return 返回商品分类集合
     */
    @GetMapping("list/ids")
    public ResponseEntity<List<Category>> queryByIds(@RequestParam("ids") List<Long> ids) {
        return ResponseEntity.ok(categoryService.queryByIds(ids));
    }

}
